package com.api.hg.util;

import com.api.sw.duban.util.LogTool;
import weaver.conn.RecordSet;
import weaver.general.Util;

public class XzUtil {
    private final static LogTool log = new LogTool("/log/assetlog/luolf/XzUtil",false);
    public static String getSwExidBySwid(String swid){
        swid= Util.null2String(swid).trim();
        if("".equals(swid)){
            return "";
        }
        String swexid="";
        RecordSet re=new RecordSet();
        String sql="select * from uf_swnewexception where isnull(sfyxz,-1) in (-1,1) and swzcid='"+swid+"'";
        log.writeLog("getSwExidBySwid>"+sql);
        re.execute(sql);
        if(re.next()){
            swexid=Util.null2String(re.getString("id"));
        }
        return swexid;
    }

    public static String getGbExidByGbid(String gbid){
        gbid= Util.null2String(gbid).trim();
        if("".equals(gbid)){
            return "";
        }
        String swexid="";
        RecordSet re=new RecordSet();
        String sql="select * from uf_uf_gbxtzczmxxexc where isnull(sfyxz,-1) in (-1,1) and gbzcid='"+gbid+"'";
        log.writeLog("getGbExidByGbid>"+sql);
        re.execute(sql);
        if(re.next()){
            swexid=Util.null2String(re.getString("id"));
        }
        return swexid;
    }

    /**
     * 将字符串  用逗号隔开
     * @param str
     * @return
     */
    public static String getStrDh(String str){
        str=Util.null2String(str).trim();
        String newstr="";
        if("".equals(str)){
            return "";
        }
        String [] strs=str.split(",");
        for(String demo:strs){
            demo=Util.null2String(demo).trim();
            if("".equals(demo)){
                continue;
            }
            newstr=newstr+"'"+demo+"',";
        }
        if(newstr.endsWith(",")){
            newstr=newstr.substring(0,newstr.length()-1);
        }
        return newstr;
    }

    /**
     * 销账  校验数据  实物  关保  必须是资产异常表为 销账数据
     * @param swzc  实物
     * @param gbzc  关保
     * @return
     */
    public static boolean ckeckCanle(String swzc,String gbzc){
        swzc=Util.null2String(swzc).trim();
        gbzc=Util.null2String(gbzc).trim();
        if("".equals(swzc)){
            return false;
        }
        if("".equals(gbzc)){
            return false;
        }
        RecordSet re=new RecordSet();
        //String sql="select 1 from uf_swnewexception where isnull(sfyxz,-1) in (1,-1) and swzcid="+swzc;
        String sql="select 1 from uf_swnewexception where  swzcid="+swzc;
        log.writeLog("销账校验实物是否为实物异常表数据>"+sql);
        re.execute(sql);
        if(!re.next()){
            return false;
        }
        sql="select 1 from uf_uf_gbxtzczmxxexc where kpwybs='"+gbzc+"'";
        log.writeLog("销账校验关保是否为关保异常数据>"+sql);
        re.execute(sql);
        if(!re.next()){
            return false;
        }
        return true;
    }
}
